/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */

package com.android.music.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.music.R;
import com.android.music.util.MusicOperate;

public class TypeMusicListAdapter extends BaseAdapter {

    private Context mContext;

    private Cursor cursor;

    public TypeMusicListAdapter(Context con, Cursor cursor) {
        mContext = con;
        this.cursor = cursor;
    }

    public int getCount() {
        return cursor.getCount();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return position;
    }

    private TextView lineItemDuration;

    private TextView lineItemName;

    private TextView lineItemDescription;

    public View getView(int position, View convertView, ViewGroup parent) {
        cursor.moveToPosition(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.lineitem, null);
        }
        lineItemDuration = (TextView) convertView.findViewById(R.id.LineItemDuration);
        lineItemName = (TextView) convertView.findViewById(R.id.LineItemName);
        lineItemDescription = (TextView) convertView.findViewById(R.id.LineItemDescription);
        lineItemDuration.setText(MusicOperate.toTime(cursor.getInt(8)));
        lineItemDescription.setText(cursor.getString(1));
        if (cursor.getString(1).equals("<unknown>"))
            lineItemDescription.setText(R.string.unknown_artist_name);
        lineItemName.setText(String.valueOf(position + 1) + "、" + cursor.getString(3));
        return convertView;
    }

}
